﻿using ComClassLibrary;
using LogLib;
using System;
using System.Windows;
using KeyboardArg;

namespace CalendarBoard
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (e.Args.Length <= 0)
            {
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                return;
            }
            string jsonString = e.Args[0].Replace('@', '"');
            Log.WriteAsync("Json:" + jsonString);
            KeyBoardArgs KeyBoardArgs = null;
            try
            {
                KeyBoardArgs = JsonHandler.ConvertToJsonObject<KeyBoardArgs>(jsonString);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                MessageBox.Show(ex.ToString(), "参数错误");
            }
            if (null == KeyBoardArgs)
            {
                MessageBox.Show(jsonString, "参数错误"); 
                return;
            }
            else
            {
                MainWindow mainWindow = new MainWindow(KeyBoardArgs);                
                mainWindow.Show();
            }
        }   
    }
}
